From 0d8e7eeb35edaa346537d8ec77fe11670be62149 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sun, 10 Oct 2021 15:54:44 -0600 Subject: [PATCH] migrate from QRegExp to QRegularExpression. (#729) --- csv_util.cc | 31 ++++++++++++++++++++----------- csv_util.h | 4 +++- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/csv_util.cc b/csv_util.cc index 70bad0d66..33128e756 100644 --- a/csv_util.cc +++ b/csv_util.cc @@ -20,18 +20,23 @@ */ -#include // for fabs -#include // for size_t -#include // for atof, strtod -#include // for isspace -#include // for strlen, strchr, strncmp, strcmp, memmove, strcpy, strcspn, strncpy - -#include // for QRegExp -#include // for QString +#include // for assert +#include // for isspace +#include // for fabs +#include // for size_t +#include // for atof, strtod +#include // for strlen, strchr, strncmp, strcmp, memmove, strcpy, strcspn, strncpy + +#include // for QChar +#include // for QDebug +#include // for QRegularExpression +#include // for QString, operator+ +#include // for QStringRef #include "defs.h" #include "csv_util.h" -#include "src/core/logging.h" +#include "src/core/logging.h" // for Warning + #define MYNAME "CSV_UTIL" @@ -48,8 +53,12 @@ QString csv_stringclean(const QString& source, const QString& to_nuke) { QString r = source; - QString regex = QString("[%1]").arg(to_nuke); - return r.remove(QRegExp(regex)); + // avoid problematic regular rexpressions, e.g. xmapwpt generated [:\n:], + // or one can imagine [0-9] when we meant the characters, '0', '-', and '9', + // or one can imagine [^a] when we meant the characters '^' and 'a'. + QRegularExpression regex = QRegularExpression(QString("[%1]").arg(QRegularExpression::escape(to_nuke))); + assert(regex.isValid()); + return r.remove(regex); } // csv_stringtrim() - trim whitespace and leading and trailing diff --git a/csv_util.h b/csv_util.h index 3980db4ce..4ea9fa0be 100644 --- a/csv_util.h +++ b/csv_util.h @@ -21,10 +21,12 @@ #ifndef CSV_UTIL_H_INCLUDED_ #define CSV_UTIL_H_INCLUDED_ -#include // for QString +#include // for QString +#include // for QStringList #include "defs.h" + /* function prototypes */ QString -- 2.30.2